package com.cjq.project.controller;

import com.cjq.common.domain.DTO.ProjectDTO;
import com.cjq.common.domain.Fee;
import com.cjq.common.domain.Project;
import com.cjq.common.domain.request.ProjectReq;
import com.cjq.common.domain.response.ProjectRes;
import com.cjq.common.result.PageResult;
import com.cjq.common.result.Result;
import com.cjq.project.service.ProjectService;
import com.cjq.project.util.OssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/project")
public class ProjectController {
    @Autowired
    private ProjectService projectService;
    @Autowired
    private OssUtil ossUtil;

    /**
     * 項目列表
     * @param projectReq
     * @return
     */
    @PostMapping("/projectList")
    public Result<PageResult<ProjectRes>> projectList(@RequestBody ProjectReq projectReq){
        return projectService.projectList(projectReq);
    }

    /**
     * 成品类型
     * @return
     */
    @GetMapping("/feeList")
    public Result<List<Fee>> feeList(){
        return projectService.feeList();
    }

    /**
     * 添加
     * @param projectDTO
     * @return
     */
    @PostMapping("/insert")
    public boolean insert(@RequestBody ProjectDTO projectDTO){
        return projectService.insert(projectDTO);
    }

    /**
     * 图片上传
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result<String> upload(@RequestParam("file")MultipartFile file){
        String filePath = OssUtil.uploadMultipartFile(file);
        return Result.success(filePath);
    }
}
